function setUserDetail(item) {

    $("#user-detail-box").empty();
    $("#user-detail-box").load("/user/userDetail?id="+item);
}

function addUser() {

    var params = {};

    params.userName = $("#userName").val();
    params.password = $("#password").val();
    params.staffNo = $("#staffno").val();
    params.state = $("#state").val();


    if(params.userName === null||params.userName===''){
        alert("账户名不得为空");
        return false;
    }
    if(params.password === null||params.password===''){
        alert("密码不得为空");
        return false;
    }
    if(params.staffNo === null||params.staffNo===''){
        alert("工号不得为空");
        return false;
    }

    $.ajax({
        type: 'POST',
        url: "/user/addUser",
        contentType:"application/json",
        data: JSON.stringify(params),
        success: function (result) {
            if(result==='success') {
                alert("新增账户成功成功");
                $("#user").click();
            }
            else if(result==='userExists'){
                alert("用户名已存在");
            }
            else{
                alert(result)
            }
        },
        dataType: "text"
    });
    
}

function  editUser(_this) {

    $("#submit").removeAttr("disabled");
    $("#password").removeAttr("disabled");
    $("#staffno").removeAttr("disabled");
    $("#state").removeAttr("disabled");

}

function updateUser() {

    var params = {};

    params.id = $("#userId").val();
    params.password = $("#password").val();
    params.staffNo = $("#staffno").val();
    params.state = $("#state").val();

    $.ajax({
        type: 'POST',
        url: "/user/updateUser",
        contentType:"application/json",
        data: JSON.stringify(params),
        success: function (result) {
            alert("更新账户信息成功");
            $("#user").click();
        },
        dataType: "text"
    });

}